public class Myqueue {
    class Node{
        public int val;
        public Node next;
        public Node(int val){
            this.val=val;
        }
    }

    public Node head;
    public Node last;
    public int size;

    public void offer(int val){
        Node node = new Node(val);
        if(head==null){
            head=node;
            last=node;
        }else{
            last.next=node;
            last=node;
        }
        size++;
    }
    public int poll(){
        if(empty()){
            throw new EmptyException("队列为空");
        }
        int ret=head.val;
        head=head.next;
        size--;
        return ret;
    }
    public boolean empty(){
        return size==0;
    }
    public int peek(){
        if(empty()){
            throw new EmptyException("队列为空");
        }
        int ret=head.val;
        return ret;
    }
}
